# Maintainer: AlexWMF <alexxwmf@gmail.com>

_realname=libvmime
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r1270.d03ad5f0
_commit=d03ad5f0f6d3b2d54009ccdc7d1f7670218b263c
pkgrel=2
pkgdesc="An open source solution for working with MIME messages and Internet messaging services like IMAP, POP or SMTP (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.vmime.org/"
msys2_repository_url="https://github.com/kisli/vmime"
license=('spdx:GPL-3.0-or-later')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gsasl"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         #"${MINGW_PACKAGE_PREFIX}-openssl"
        )
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-iconv"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "git")
source=("${_realname}"::"git+https://github.com/kisli/vmime.git#commit=$_commit"
        cmake_mlang.patch)
sha256sums=('SKIP'
            '43f137580cade0322aa1c36c1fdea37b2a2b805839c56d935826f9153bfcbbfa')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count $_commit)" "$(git rev-parse --short $_commit)"
}

prepare() {
  cd "${_realname}"
  patch -p1 -i "${srcdir}"/cmake_mlang.patch
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  LDFLAGS+=" -Wl,--export-all-symbols"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${_extra_config[@]}" \
    -DVMIME_HAVE_MESSAGING_PROTO_SENDMAIL=OFF \
    -DVMIME_BUILD_SAMPLES=OFF \
    -DVMIME_TLS_SUPPORT_LIB=gnutls \
    -DVMIME_CHARSETCONV_LIB=iconv \
    ../${_realname}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd build-${MSYSTEM}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}"/${_realname}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
